package 测试;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Test4 {
    public static void main(String[] args) {
        try {
            String python_env_path = "G:\\ANACONDA\\envs\\uxnet3d_4\\python.exe";
            String py_path = "D:\\jupyter_document\\uxnet3d_2\\3DUX-Net\\test_seg.py";
            String data_path = "D:\\jupyter_document\\uxnet3d_2\\3DUX-Net\\data";
            String output = "D:\\jupyter_document\\uxnet3d_2\\3DUX-Net\\output";
            String model_path = "D:\\jupyter_document\\uxnet3d_2\\3DUX-Net\\test\\model\\best_metric_model.pth";

            ProcessBuilder pb = new ProcessBuilder(
                    "G:\\ANACONDA\\envs\\uxnet3d_4\\python.exe",
                    "D:\\jupyter_document\\uxnet3d_2\\3DUX-Net\\test_seg.py",
                    "--root", "D:\\jupyter_document\\uxnet3d_2\\3DUX-Net\\data",
                    "--output", "D:\\jupyter_document\\uxnet3d_2\\3DUX-Net\\output",
                    "--dataset", "flare",
                    "--network", "3DUXNET",
                    "--trained_weights", "D:\\jupyter_document\\uxnet3d_2\\3DUX-Net\\test\\model\\best_metric_model.pth",
                    "--mode", "test",
                    "--sw_batch_size", "4",
                    "--overlap", "0.7",
                    "--gpu", "0",
                    "--cache_rate", "0.2"
            );
            System.out.println(pb);
            Process process = pb.start();

            // 从进程的输出流中读取输出
            BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
            String line;
            while ((line = reader.readLine()) != null) {
                System.out.println(line); // 打印输出
            }

            // 等待进程结束
            int exitCode = process.waitFor();
            System.out.println("Process exited with code " + exitCode);

            // 确保进程的输出流被关闭，以防止死锁
            reader.close();

        } catch (IOException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt(); // 重置中断状态
            e.printStackTrace();
        }
    }
}
